home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / IPRSRTST.C < prev    next >
C/C++ Source or Header  |  1992-01-28  |  9KB  |  310 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Test program of the InptPrsr.c module:                     *
  7. * Note you can set DEBUG for InptPrsr preprocessor for intermidiate results: *
  8. *****************************************************************************/
  9.  
  10. #ifdef __MSDOS__
  11. #include <stdlib.h>
  12. #include <conio.h>
  13. #include <alloc.h>
  14. #endif /* __MSDOS__ */
  15.  
  16. #include <stdio.h>
  17. #include <setjmp.h>
  18. #include "program.h"
  19. #include "inptprsg.h"
  20. #include "dosintr.h"
  21. #include "matherr.h"
  22.  
  23. char CurrentWorkingDir[LINE_LEN];      /* Save start CWD to recover on exit. */
  24.  
  25. ObjectStruct *GlblObjList = NULL;       /* All objects defined on system. */
  26.  
  27. int  GlblWasCtrlBrk = FALSE;          /* True if control break/C was pressed. */
  28. int  GlblFatalError = FALSE;      /* True if disaster in system - must quit! */
  29. int  GlblLoadColor = 1,
  30.      GlblBoolColor = 2,
  31.      GlblICrvColor = 14,
  32.      GlblPrimColor = 4;
  33.  
  34. char *GlblHelpFileName = "irit.hlp";
  35.  
  36. jmp_buf GlblLongJumpBuffer;                  /* Used in error recovery. */
  37.  
  38. #ifdef __MSDOS__
  39. extern unsigned int _stklen = 16384;         /* Increase default stack size. */
  40. #endif /* __MSDOS__ */
  41.  
  42. static void PrintInptPrsrError(void);
  43.  
  44. /*****************************************************************************
  45. * Simple main routine to emulate the needed parameters for InputParser:      *
  46. *****************************************************************************/
  47. void main(void)
  48. {
  49.     SetUpPredefObjects();          /* Prepare the predefined objects. */
  50.     fprintf(stderr, "Input Parser Test Program (type expression follows by ';'):\n");
  51.  
  52.     DosGetTime(1.0);                    /* Reset the time count. */
  53.     AliasReset();
  54.  
  55.     /* If one long jumped to here with value 2, we must quit the program!    */
  56.     if (setjmp(LongJumpBuffer) == 2)              /* Used in error recovery. */
  57.     exit(1);
  58.  
  59.     while (TRUE) {                          /* Do forever. */
  60.     if (!InputParser())             /* Error was found - handle it. */
  61.         PrintInptPrsrError();
  62.     fprintf(stderr, "\nCurrent defined objects (Core left = %lx) :\n",
  63.                                 coreleft());
  64.     PrintObjectList(GlblObjList);
  65.     }
  66. }
  67.  
  68. /*****************************************************************************
  69. * Routine to query (and print) the errors found in InputParser:             *
  70. *****************************************************************************/
  71. static void PrintInptPrsrError(void)
  72. {
  73.     InptPrsrEvalErrType ErrorNum;
  74.     char *ErrorMsg;
  75.  
  76.     if ((ErrorNum = InptPrsrParseError(&ErrorMsg)) != IPE_NO_ERR) {/*Prsr err*/
  77.     fprintf(stderr, "Parsing Error: ");
  78.     switch (ErrorNum) {
  79.         case IP_ERR_WRONG_SYNTAX:
  80.         fprintf(stderr, "Wrong syntax\n");
  81.         break;
  82.         case IP_ERR_PARAM_EXPECT:
  83.         fprintf(stderr, "Parameter Expected - %s\n", ErrorMsg);
  84.         break;
  85.         case IP_ERR_ONE_OPERAND:
  86.         fprintf(stderr, "Wrong Number of operands (1) - %s\n", ErrorMsg);
  87.         break;
  88.         case IP_ERR_TWO_OPERAND:
  89.         fprintf(stderr, "Wrong Number of operands (2) - %s\n", ErrorMsg);
  90.         break;
  91.         case IP_ERR_STACK_OV:
  92.         fprintf(stderr, "Internal Stack OverFlow at - %s\n", ErrorMsg);
  93.         break;
  94.         case IP_ERR_PARAM_MATCH:
  95.         fprintf(stderr, "Parenthesis mismatch - %s\n", ErrorMsg);
  96.         break;
  97.         case IP_ERR_UNDEF_TOKEN:
  98.         fprintf(stderr, "Undefined token - %s\n", ErrorMsg);
  99.         break;
  100.         case IP_ERR_UNDEF_FUNC:
  101.         fprintf(stderr, "Undefined function - %s\n", ErrorMsg);
  102.         break;
  103.         case IP_ERR_NAME_TOO_LONG:
  104.         fprintf(stderr, "Object name too long - %s\n", ErrorMsg);
  105.         break;
  106.         case IP_ERR_PARAM_FUNC:
  107.         fprintf(stderr, "Parameters expected in func %s\n", ErrorMsg);
  108.         break;
  109.         case IP_ERR_NO_PARAM_FUNC:
  110.         fprintf(stderr, "No Parameters expected in func %s\n", ErrorMsg);
  111.         break;
  112.     }
  113.     return;
  114.     }
  115.  
  116.     if ((ErrorNum = InptPrsrEvalError(&ErrorMsg)) != IPE_NO_ERR) {/*Eval err.*/
  117.     fprintf(stderr, "Eval Error: ");
  118.     switch (ErrorNum) {
  119.         case IE_ERR_FATAL_ERROR:
  120.         fprintf(stderr, "Fatal Error - %s\n", ErrorMsg);
  121.         break;
  122.         case IE_ERR_DIV_BY_ZERO:
  123.         fprintf(stderr, "Division by zero - %s\n", ErrorMsg);
  124.         break;
  125.         case IE_ERR_NO_OBJ_METHOD:
  126.         fprintf(stderr, "No such method for object - %s\n", ErrorMsg);
  127.         break;
  128.         case IE_ERR_TYPE_MISMATCH:
  129.         fprintf(stderr, "Parameter type mismatch - %s\n", ErrorMsg);
  130.         break;
  131.         case IE_ERR_ASSIGN_LEFT_OP:
  132.         fprintf(stderr, "Lval is not a parameter - %s\n", ErrorMsg);
  133.         break;
  134.         case IE_ERR_MIXED_OBJ:
  135.         fprintf(stderr, "Mixed types in expression - %s\n", ErrorMsg);
  136.         break;
  137.         case IE_ERR_UNDEF_OBJECT:
  138.         fprintf(stderr, "No such object defined - %s\n", ErrorMsg);
  139.         break;
  140.         case IE_ERR_NO_ASSIGNMENT:
  141.         fprintf(stderr, "Assignment was expected\n");
  142.         break;
  143.         case IE_ERR_FP_ERROR:
  144.         fprintf(stderr, "Floating Point Error - %s\n", ErrorMsg);
  145.         break;
  146.         case IE_ERR_NUM_PRM_MISMATCH:
  147.         fprintf(stderr, "Number of func. param. mismatch - %s\n", ErrorMsg);
  148.         break;
  149.         case IE_ERR_MAT_POWER:
  150.         fprintf(stderr, "Wrong range or result exists, operator - %s\n", ErrorMsg);
  151.         break;
  152.         case IE_ERR_FREE_SIMPLE:
  153.         fprintf(stderr, "Free only Geometric Objects - %s\n", ErrorMsg);
  154.         break;
  155.         case IE_ERR_MODIF_ITER_VAR:
  156.         fprintf(stderr,
  157.             "Iteration var. type modified or freed - %s\n", ErrorMsg);
  158.         break;
  159.         case IE_ERR_BOOLEAN_ERR:
  160.         fprintf(stderr,
  161.             "Geometric Boolean operation error - %s\n", ErrorMsg);
  162.         break;
  163.         case IE_ERR_LIST_TOO_LONG:
  164.         fprintf(stderr,
  165.             "List length too big - up to %d only.\n", MAX_OBJ_LIST);
  166.         break;
  167.         case IE_ERR_DATA_PRSR_ERROR:
  168.         fprintf(stderr, "%s", ErrorMsg);
  169.         break;
  170.     }
  171.     return;
  172.     }
  173. }
  174.  
  175. /*****************************************************************************
  176. * MyExit routine.                                  *
  177. *****************************************************************************/
  178. void MyExit(int ExitCode)
  179. {
  180.     exit(ExitCode);
  181. }
  182.  
  183. /*****************************************************************************
  184. * FatalEror routine. same as MyExit routine, but print error message         *
  185. * before it dies.                                 *
  186. *****************************************************************************/
  187. void FatalError(char *ErrorMsg)
  188. {
  189.     fprintf(stderr, "%s\n", ErrorMsg);
  190.  
  191.     exit(99);
  192. }
  193.  
  194. /*****************************************************************************
  195. *   Routine that is called from the floating point package in case of fatal  *
  196. * floating point error. Print error message, long jump to main loop. Default *
  197. * FPE handler - must be reset after redirected to other module.             *
  198. *****************************************************************************/
  199. #ifdef __MSDOS__
  200. void DefaultFPEHandler(int Sig, int Type, int *RegList)
  201. #else
  202. void DefaultFPEHandler(int Type)
  203. #endif /* __MSDOS__ */
  204. {
  205.     PrintFPError(Type);             /* Print the floating point error type. */
  206.  
  207.     longjmp(LongJumpBuffer, 1);
  208. }
  209.  
  210. /*****************************************************************************
  211. *  And other emulations to the routines:                     *
  212. *****************************************************************************/
  213. void WndwPause()
  214. {
  215.     fprintf(stderr, "Pause was called, press anything:");
  216.     getch();
  217. }
  218.  
  219. void WndwInputWindowGetStr(char *Str, int Length)
  220. {
  221.     gets(Str);
  222. }
  223.  
  224. void WndwLogPrint(RealType *R)
  225. {
  226.     fprintf(stderr, "Log file toggle - value = %lf\n", *R);
  227. }
  228.  
  229. void WndwInputWindowPutStr(char *Str, int Color)
  230. {
  231.     printf("%s\n", Str);
  232. }
  233.  
  234. void WndwInputWindowPutStrFS(char *Str, int Color, int Reset)
  235. {
  236.     printf("%s\n", Str);
  237. }
  238.  
  239. void WndwViewGeomObject(ObjectStruct *PObj, RealType *ClearScreen)
  240. {
  241.     fprintf(stderr,
  242.     "VIEW: object %s (Clear = %g)\n", PObj->Name, *ClearScreen);
  243. }
  244.  
  245. void WndwStatusWindowUpdate()
  246. {
  247.     fprintf(stderr, "Core left = %lx\n", coreleft());
  248. }
  249.  
  250. void DosChangeDir(char *s)
  251. {
  252.     fprintf(stderr, "CHDIR: to directory %s\n", s);
  253. }
  254.  
  255. double DosGetTime(double ResetTime)
  256. {
  257.     fprintf(stderr, "Time invoked with reset = %lf\n", ResetTime);
  258.     return 1234.5678;
  259. }
  260.  
  261. void DosEditFile(char *s)
  262. {
  263.     fprintf(stderr, "Edit invoked with file \"%s\"\n", s);
  264. }
  265.  
  266. void DosSystem()
  267. {
  268.     fprintf(stderr, "System invoked\n");
  269. }
  270.  
  271. void DosPrintDir(char *s)
  272. {
  273.     fprintf(stderr, "Print Dir entered (%s)\n", s);
  274. }
  275.  
  276. void InteractPolyObject(ObjectStruct *PObj, RealType *UpdateGlblMat)
  277. {
  278.     fprintf(stderr, "View Object entered, object %s, Update= %lf\n",
  279.                         PObj -> Name, *UpdateGlblMat);
  280. }
  281.  
  282. void ViewGeomObject(ObjectStruct *PObj)
  283. {
  284.     fprintf(stderr, "View Object entered, object %s\n", PObj -> Name);
  285. }
  286.  
  287. void ViewSetNormals(RealType *Active, RealType *Size, RealType *Color)
  288. {
  289.     fprintf(stderr,
  290.     "View set normals entered, Active = %g Size = %g Color = %g\n",
  291.         *Active, *Size, *Color);
  292. }
  293.  
  294. void GGTone(int Freq, int Time)
  295. {
  296.     fprintf(stderr, "Beep invoked, Freq = %d, Time = %d\n", Freq, Time);
  297. }
  298.  
  299. #ifndef __MSDOS__
  300. getch()
  301. {
  302.     fprintf(stderr, "GetCh has been invoked.\n");
  303. }
  304.  
  305. coreleft()
  306. {
  307.     return 100000;
  308. }
  309. #endif /* __MSDOS__ */
  310.